package com.xxx.mysql.student.mangaer;

import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;

public class TestStudentManager {
    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    public static void main(String[] args) {

        System.out.println(new java.sql.Date(System.currentTimeMillis()));
        boolean flag = true;
        while (flag) {


            System.out.println("*************学生管理*************");
            System.out.println("1. 添加学生信息");
            System.out.println("2. 删除学生信息");
            System.out.println("3. 修改学生信息");
            System.out.println("4. 查询学生信息");
            System.out.println("5. 退出");

            Scanner sc = new Scanner(System.in);

            System.out.println("请选择操作：");
            int key = sc.nextInt();
            switch (key) {
                case 1:
                    System.out.println("请输入学生信息：");
                    //111,黄宗伟,男,1998-08-14,99999
                    String message = sc.next();
                    String[] str = message.split(",");
                    String birthday = str[3];

                    StudentInfo st = null;

                    try {
                        st = new StudentInfo(str[0], str[1], str[2], sdf.parse(birthday), str[4]);
                        OperationStudent.addStudent(st);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    break;

                case 2:
                    System.out.println("请选择你要删除的学生信息的学生ID");
                    int id1 = sc.nextInt();
                    OperationStudent.deleteStudent(id1);
                    break;

                case 3:
                    System.out.println("请选择你要修改的学生信息的学生ID");
                    int id2 = sc.nextInt();
                    System.out.println("请按顺序输入该学生的所有信息，不用修改的信息按原信息重新输入");
                    String stInfo = sc.next();
                    String[] strArr = stInfo.split(",");
                    String updateBirthday = strArr[3];
                    StudentInfo st1 = null;
                    try {
                        st1 = new StudentInfo(strArr[0], strArr[1], strArr[2], sdf.parse(updateBirthday), strArr[4]);

                        OperationStudent.updateStudent(id2, st1);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    break;

                case 4:
                    System.out.println("请选择你要查找的学生信息的学生ID");
                    int id3 = sc.nextInt();

                    OperationStudent.queryStudent(id3);
                    break;

                case 5:
                    System.out.println("是否退出（Y 或者 N");
                    String choise = sc.next();
                    String s = choise.toUpperCase();
                    if (s.equals("Y")) {
                        flag = false;
                        return;
                    }
                    if (s.equals("N")) {

                    }
                    break;

                default:
                    System.out.println("输入有误");
                    break;
            }
        }
    }

}
